<template>
  <a-row>
    <a-table
      ref="table"
      size="middle"
      bordered
      row-key="index"
      :columns="columns"
      :data-source="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
    >
      <template slot="fileName" slot-scope="text, record, index">
        <j-ellipsis :value="text" :length="20"/>
      </template>
      <template slot="status" slot-scope="text, record">
        <a-tag v-if="text=='1'" color="green">
          已导入
        </a-tag>
        <a-tag v-if="text=='0'">
          未导入
        </a-tag>
      </template>
      <template slot="action" slot-scope="text, record">
        <a-button @click="OnPerview(record)" title="预览">预览</a-button>
        <a-button @click="OnPerviewTemp(record)" title="模板预览" style="margin-left:5px">模板预览</a-button>
      </template>
    </a-table>
  </a-row>
</template>

<script>

  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import columns from './columns'
  import {Base64} from 'js-base64'

  export default {
    name: 'PerviewForm',
    components: {},
    mixins: [JeecgListMixin],
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data() {
      return {
        columns: columns(),
        confirmLoading: false,
        disableMixinCreated: true,
        queryParam: {},
        url: {
          list: '/sjcj/dataCollectionTaskDetail/list',
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
    created() {
    },
    methods: {
      OnPerview(record) {
        let fileUrl = `${window._CONFIG['onlinePreviewFileURL']}/sys/common/static${record.path}`
        // let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(fileUrl)}`
        let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(Base64.encode(fileUrl))}`
        window.open(url, '_blank')
      },
      OnPerviewTemp(record) {
        let fileUrl = `${window._CONFIG['onlinePreviewFileURL']}/sys/common/static${record.modelPath}`
        // let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(fileUrl)}`
        let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(Base64.encode(fileUrl))}`
        window.open(url, '_blank')
      },
      edit(record) {
        this.queryParam = {taskId: record.id}
        this.loadData(1)
        this.visible = true
      }
    }
  }
</script>
<style scoped>
  .title {
    width: 20%;
    font-weight: bold;
    font-size: 15px;
    margin-bottom: 15px;
    color: #3955a5;
  }
</style>
